<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>地址管理 - 小憨堡</title>
        <script src="../static/js/jquery-3.2.1.js"></script>
        <link rel="stylesheet" href="../static/bootstrap-3.3.7-dist/css/bootstrap.css" />
        <link rel="stylesheet" href="../static/css/style.css" />
        <script>
            $(document).ready(function () {
                $.get(
                    "/currentUser",
                    function (data, status) {
                        if (data.code == 0) {
                            $("#top-nav").append("<li><a href=\"logout\" style='font-size: 12px;'>你好：" + data.data + " (退出登录)</a></li>\n" +
                                "                    <li><a href=\"account.html\">账号管理</a></li>\n" +
                                "                    <li><a href=\"address.html\">地址管理</a></li>" +
                                "                    <li><a href=\"index.html\">首页</a></li>\n"
                            );
                        } else {
                            $("#top-nav").append("<li><a href=\"login.html\">登录</a></li>");
                        }
                    }
                );
                $("#current-address").load("/currentUser/address");
            });
            function updateAddress() {
                if (!confirm("收货地址每30天只能更改一次，确认要修改吗？")) return;
                $.post(
                    "/user/address/update",{
                        address: $("#address").val()
                    }, function (data, status) {
                        if (data.code == 0) {
                            alert("修改成功！");
                            window.location = "/address.html";
                        } else {
                            alert("修改失败！");
                        }
                    }
                );
            }
        </script>
    </head>
    <body>
        <div class="login-bg">
        </div>
        <div class="topbar">
            <img src="../static/images/index-logo.png" />
            <ul id="top-nav">

            </ul>
        </div>
        <div class="container">
            <div class="login-header">更改收货地址</div>
            <div class="form-group">
                你当前的收货地址：<span id="current-address"></span>
            </div>
            <div class="form-group">
                输入新收货地址：<input type="text" id="address" class="form-control" />
            </div>
            <button class="btn btn-success form-control" onclick="updateAddress()">提交</button>
            <div class="form-group"></div>
        </div>
        <div class="sidebar-footer">
            <p class="copyright">Copyright &copy; 2020. Group 6 All rights reserved.</p>
        </div>
    </body>
</html>